#include "stdio.h"

extern const char* VGA_BUFFER;
 
const static char * STD_OUT = (const char*)0x07e00; //输出缓存开始地址

int strcpy(void* dest, void *source)
{
	char *des = (char*)dest;
	char* sour = (char*)source;
	while (des && *sour != '\0')
	{
		*des++ = *sour++;
	}
	*des = '\0';
	return des - (char*)dest;
}

static unsigned int current_std_out_offset = 0;
void printf(const char*str)
{
	current_std_out_offset += strcpy((void*)(STD_OUT + current_std_out_offset), (void*)str);
}

void flush()
{
	cmd_cls();//clear
	unsigned int i = 0, ii = 0;
	char* out = VGA_BUFFER;
	out = VGA_BUFFER;
	char* out_buffer = (char*)STD_OUT;
	for (i = 0, ii = 0; '\0' != out_buffer[ii] && ii < VGA_BUFFER_MAX_OFFSET; ii++)
	{// left-up is (0,0);
		if (out_buffer[ii] == '\n')
		{
			i = (i / (VGA_X_BUFFER_SIZE)+1) * VGA_X_BUFFER_SIZE;
			continue;
		}
		out[i++] = out_buffer[ii];
		out[i++] = 0x0f;

	}
	current_std_out_offset = 0;
}